home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / ai.prl / mike1.exe / FLU2.KB < prev    next >
Encoding:
Text File  |  1990-09-14  |  6.5 KB  |  191 lines

  1.  
  2. /* FLU2.KB-- like FLU.KB, but uses ask_menu to prompt user
  3. (See end of file for 'HOW TO RUN' info)
  4.  
  5. Elementary (rule-based) medical diagnosis.
  6. The purpose of this file is to get you used to
  7. the rule notation.  More sophisticated diagnosis
  8. would ordinarily use MIKE's frame system.
  9.  
  10. Example symptom descriptors might be as follows
  11.  
  12. Alice has a dry throat, a muzzy feeling in the head, a runny nose, sneezing
  13. and a slight transient fever, i.e. nothing worse than the common cold.  In
  14. MIKE list style syntax this would look like the following :
  15.  
  16. [alice, exhibits_symptom, dry_throat]
  17. [alice, exhibits_symptom, muzzy_feeling_head]
  18. [alice, exhibits_symptom, runny_nose]
  19. [alice, exhibits_symptom sneezing]
  20. [alice, exhibits_symptom, slight_transient_fever]
  21.  
  22. Bert has a blocked and runny nose, he is sneezing, and his eyes are red,
  23. itchey, and watering.  Bert is thus a hay-fever sufferer.  The MIKE for the
  24. following is listed below.
  25.  
  26. [bert, exhibits_symptom, runny_nose]
  27. [bert, exhibits_symptom, blocked_nose]
  28. [bert, exhibits_symptom sneezing]
  29. [bert, exhibits_symptom, red_itchy_watery_eyes]
  30.  
  31. Another sufferer of the common cold in Charlie.  He has a dry throat, a
  32. muzzy feeling in the head, a runny nose and sneezing, and has a slight
  33. transient fever.  A MIKE version follows.
  34.  
  35. [charlie, exhibits_symptom, dry_throat]
  36. [charlie, exhibits_symptom, muzzy_feeling_head]
  37. [charlie, exhibits_symptom, runny_nose]
  38. [charlie, exhibits_symptom sneezing]
  39. [charlie, exhibits_symptom, slight_transient_fever]
  40.  
  41. Poor Donna's got laryngitis.  Her symptoms are a persistent dry cough, a
  42. hoarse voice, laryngeal discomfort, slight transient fever, and malaise.
  43. A MIKE version follows:-
  44.  
  45. [donna, exhibits_symptom, persistent_dry_cough]
  46. [donna, exhibits_symptom, hoarse_voice]
  47. [donna, exhibits_symptom, laryngeal_discomfort]
  48. [donna, exhibits_symptom, slight_transient_fever]
  49. [donna, exhibits_symptom, malaise]
  50.  
  51. Eva has influenza.  She has a persistent dry cough, a sore throat, slight
  52. transient fever, shivering, malaise, a headache, and is suffering from diffuse
  53. aches and pains.
  54.  
  55. [eva, exhibits_symptom, persistent_dry_cough]
  56. [eva, exhibits_symptom, sore_throat]
  57. [eva, exhibits_symptom, slight_transient_fever]
  58. [eva, exhibits_symptom shivering]
  59. [eva, exhibits_symptom, malaise]
  60. [eva, exhibits_symptom, headache]
  61. [eva, exhibits_symptom, aches_and_pains]
  62.  
  63. Finally Frank has seasonal allergic rhinitis, better known as hay fever.
  64. He has a runny nose, a blocked nose, sneezing, and soar red eyes.
  65.  
  66. [frank, exhibits_symptom, runny_nose]
  67. [frank, exhibits_symptom, blocked_nose]
  68. [frank, exhibits_symptom sneezing]
  69. [frank, exhibits_symptom, red_itchy_watery_eyes].
  70.  
  71. To 'seed' working memory with the above facts, you would need to use
  72. 'add'.  For example:
  73.  
  74.   ?- add [frank, exhibits_symptom, runny_nose].
  75.   ?- add [frank, exhibits_symptom, blocked_nose].
  76.  
  77. In order for you to be able to do this easily we have added a simple
  78. menu style operation which allows you to select which symptoms
  79. a patient is exhibiting.  To do this run fc. in the normal way.
  80. You will then get prompted by a menu of possible symptoms.  From
  81. this menu you must then choose a series of options by typing the
  82. corresponding number to the symptom in the menu.  MIKE will then
  83. try to diagnose what the patient has wrong with them
  84. */
  85. /* ===============  diagnosis rule base ================== */
  86.  
  87. rule patient_initialisation_Rule forward
  88.  if
  89.    start   /* special symbol always in wm at first */
  90.  then
  91.   remove start &  /* get rid of special symbol */
  92.   query ['What is the name of the patient'] receives_answer Patient &
  93.   add [patient, Patient] &  /* record the name of the patient */
  94. /* the special primative ask_menu will add to working memory those items
  95. that you select from the menu */
  96.   announce ['What symptoms does ',Patient,' exhibit?'] &
  97.   ask_menu(Patient,exhibits_symptom,
  98.    [
  99.     dry_throat,
  100.     muzzy_feeling_head,
  101.     hoarse_voice,
  102.     laryngeal_discomfort,
  103.     persistent_dry_cough,
  104.     sore_throat,
  105.     slight_transient_fever,
  106.     shivering,
  107.     malaise,
  108.     headache,
  109.     aches_and_pains,
  110.     runny_nose,
  111.     blocked_nose,
  112.     sneezing,
  113.     red_itchy_watery_eyes
  114.    ]) &
  115.   add diagnosing.
  116.  
  117.  
  118. rule 1 forward
  119.  if [patient,Patient] &
  120.   [Patient, exhibits_symptom, runny_nose] &
  121.   [Patient, exhibits_symptom, blocked_nose] &
  122.   [Patient, exhibits_symptom, sneezing] &
  123.   [Patient, exhibits_symptom, red_itchy_watery_eyes]
  124.  then
  125.   add [Patient, exhibits_symptom, hay_fever] &   /* optional addition to working memory */
  126.   announce [Patient, ' has hay fever.'].
  127.  
  128. rule 2 forward
  129.  if
  130.   [patient,Patient] &
  131.   [Patient, exhibits_symptom, persistent_dry_cough] &
  132.   [Patient, exhibits_symptom, hoarse_voice] &
  133.   [Patient, exhibits_symptom, laryngeal_discomfort] &
  134.   [Patient, exhibits_symptom, slight_transient_fever] &
  135.   [Patient, exhibits_symptom, malaise]
  136.  then
  137.   add [Patient, exhibits_symptom, laryngitis] &
  138.   announce [Patient, ' has laryngitis.'].
  139.  
  140. rule 3 forward
  141.  if [patient,Patient] &
  142.   [Patient, exhibits_symptom, dry_throat] &
  143.   [Patient, exhibits_symptom, muzzy_feeling_head] &
  144.   [Patient, exhibits_symptom, runny_nose] &
  145.   [Patient, exhibits_symptom, sneezing] &
  146.   [Patient, exhibits_symptom, slight_transient_fever]
  147.  then
  148.   add [Patient, exhibits_symptom, a, common_cold] &
  149.   announce [Patient, ' has a common cold.'].
  150.  
  151. rule 4 forward
  152.  if
  153.   [patient,Patient] &
  154.   [Patient, exhibits_symptom, persistent_dry_cough] &
  155.   [Patient, exhibits_symptom, sore_throat] &
  156.   [Patient, exhibits_symptom, slight_transient_fever] &
  157.   [Patient, exhibits_symptom, shivering] &
  158.   [Patient, exhibits_symptom, malaise] &
  159.   [Patient, exhibits_symptom, headache] &
  160.   [Patient, exhibits_symptom, aches_and_pains]
  161.  then
  162.   add [Patient, exhibits_symptom, influenza] &
  163.   announce [Patient, ' has influenza.'].
  164.  
  165. rule stop forward
  166.   if
  167.     diagnosing     /* least specific rule, so will fire last of all */
  168.   then
  169.     remove diagnosing &
  170.     announce [nl,'All possible diagnoses have been found',nl,
  171.                  'Diagnosis complete.  BYE! ',nl] &
  172.     halt.
  173.  
  174. /*   HOW TO RUN THIS EXAMPLE
  175. after loading the above rules, (using  ?- kb 'flu2.kb'.)
  176. simply invoke the forward-chainer via
  177.    ?- fc.
  178.  
  179. The contents of working memory can be viewed at the end via
  180.    ?- show wm.
  181.  
  182. Dynamic viewing of working memory changes can be observed
  183. by toggling on tracing option number 5 as follows:
  184.    ?- tracing(5).
  185.  
  186. Finally, if you want to see how a conclusion was reached, use 'how',
  187. e.g.:
  188.    ?- how [frank, exhibits_symptom, hay_fever].
  189. */
  190.  
  191.